package Test517;

import java.util.List;

public class TestList {
    //    1.添加员工信息
    public void addEmp(List<Emp> list, Emp emp) {
        list.add(emp);
    }

    //    2.查询员工信息
    public void findAllEmp(List<Emp> list) {
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }

    //    3.根据员工姓名查询员工信息
    public Emp findEmpName(List<Emp> list, String ename) {
        for (int i = 0; i < list.size(); i++) {
            if (ename.equals(list.get(i).getName())) {
                return list.get(i);
            }
        }
        return null;
    }

    //    4.根据员工编号删除员工信息
    public void deleteEmpNumber(List<Emp> list, String number) {
        for (int i = 0; i < list.size(); i++) {
            if (number.equals(list.get(i).getNumber())) {
                list.remove(i);
                System.out.println(list);

                return;
            }
        }
    }

    //    5.根据员工编号查询员工信息
    public Emp findEmpNumber(List<Emp> list, String number) {
        for (int i = 0; i < list.size(); i++) {
            if (number.equals(list.get(i).getNumber())) {
                return list.get(i);
            }
        }
        return null;
    }


    //    6.修改员工信息
    public void updateEmp(List<Emp> list,Emp emp) {
        for (int i = 0; i < list.size(); i++) {
            if (emp.getNumber().equals(list.get(i).getNumber())) {
                list.set(i, emp);
                System.out.println(list);
            }
        }
    }
}
